package recycle.controller;

import recycle.pojo.Tradingrecord;
import recycle.service.TradingrecordService;
import recycle.utils.Page;
import recycle.vo.TradingrecordParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 描述：交易记录表 控制器
* @author 孙冉
* @date 2019/07/22
*/
@RestController
@RequestMapping("/tradingrecord")
public class TradingrecordController{
	@Resource
	private TradingrecordService tradingrecordService;
 	
 	@RequestMapping("/findById.json")
    public Tradingrecord findById(Integer recordId){
        Tradingrecord result = null;
        try {
            result = tradingrecordService.findById(recordId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：获取所有的Tradingrecord对象
     */
    @RequestMapping("/findAll.json")
    public List<Tradingrecord> findAll(){
        List<Tradingrecord> result = null;
        try {
            result = tradingrecordService.findAll();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：新增保存Tradingrecord对象
     */
    @RequestMapping("/save.json")
    public Map save(Tradingrecord tradingrecord){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存交易记录表失败");
        try {
            if(tradingrecordService.save(tradingrecord)>0){
                result.put("flag",true);
                result.put("msg","保存交易记录表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：根据主键删除交易记录表对象
     * @param recordId
     */
    @RequestMapping("/delete.json")
    public Map delete(Integer recordId){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存交易记录表失败");
        try {
            if(tradingrecordService.delete(recordId)>0){
                result.put("flag",true);
                result.put("msg","保存交易记录表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：更新交易记录表对象
     */
    @RequestMapping("/update.json")
    public Map update(Tradingrecord tradingrecord){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","更新交易记录表失败");
        try {
            if( tradingrecordService.update(tradingrecord)>0){
                result.put("flag",true);
                result.put("msg","更新交易记录表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;

    }

    /**
     * 根据不确定的条件，动态查询
     */
    @RequestMapping("/query.json")
    public List<Tradingrecord> query(TradingrecordParam param){
        List<Tradingrecord> result = null;
        try {
            result = tradingrecordService.query(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 根据不确定的条件，动态分页查询
     */
    @RequestMapping("/queryByPage.json")
    public Page queryByPage(TradingrecordParam param){
        Page result = null;
        try {
            result = tradingrecordService.queryByPage(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }
 }
